cmake_minimum_required(VERSION 3.20)

project(media_transcoder VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
# 开启ctest
enable_testing()
# 引入gtest
find_package(GTest CONFIG REQUIRED)
# 引入gtest定义的方法
include(GoogleTest)
# 引入glog
find_package(glog CONFIG REQUIRED)
# 引入ffmpeg
find_package(FFMPEG REQUIRED)
#引入代码
add_subdirectory(src)
#引入测试
add_subdirectory(test)

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")

# cpack
set(QT_DEFAULT_MAJOR_VERSION 6)
find_package(Qt6 REQUIRED COMPONENTS Core)

# 安装windows动态链接库
include(InstallRequiredSystemLibraries)
include(GNUInstallDirs)
install(TARGETS MediaTranscoder
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
message("bin value : ${CMAKE_INSTALL_BINDIR}")
file(GLOB DLLS
        "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/av*.dll"
        "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/sw*.dll"
        "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/lib*.dll"
)
message("files : ${DLLS}")

install(FILES ${DLLS} DESTINATION ${CMAKE_INSTALL_BINDIR})

if (QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(MediaTranscoder)
endif ()

install(IMPORTED_RUNTIME_ARTIFACTS glog::glog gflags::gflags
        DESTINATION ${CMAKE_INSTALL_BINDIR})

install(FILES ${PROJECT_SOURCE_DIR}/src/gui/config/setting.json;${PROJECT_SOURCE_DIR}/src/gui/config/preset.json
        DESTINATION ${CMAKE_INSTALL_BINDIR})


# 此方法依赖于 find_package(Qt6 REQUIRED COMPONENTS Core)
qt_generate_deploy_app_script(
        TARGET MediaTranscoder
        OUTPUT_SCRIPT deploy_script
        NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})

set(CPACK_PACKAGE_NAME "MyProject")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_GENERATOR "ZIP")
include(CPack)

endif ()